<?php

namespace App\Library\Junda\src;

use App\Library\Junda\JunDaApiClient;
use Illuminate\Support\Facades\Cache;

class JundaLogin
{
    /**
     *
     * //        $lo =JundaLogin::login();
     * //        $lo =EquipmentService::GetEquipmentList();
     * //        $lo =CardService::GetCardList([]);
     * $lo =CardService::GetICBalance();
     *
     * exit(json_encode($lo));
     * @return array|mixed
     */
    public static function login()
    {
        $psot=[
            'UserName'=>'15634091231',
            'Password'=>'motorola1',
            'Grant_Type'=>'password',
        ];
//        $psot=[
//            'UserName'=>'15689858152',
//            'Password'=>'l123456',
//            'Grant_Type'=>'password',
//        ];
//        $data = JunDaApiClient::sendLoginRequest('https://apiV2.ljda.net/token',json_encode($psot));
        $data = JunDaApiClient::sendRequest('https://apiV2.ljda.net/token','POST',json_encode($psot),true);
        if (isset($data['success'])){
            return ['code'=>0,'msg'=>'参数错误！'];
        }
        $access_token = $data['access_token'];
        Cache::set('login_junda_access_token', $access_token, 60*19);
        return  $access_token;
    }
}
